package com.example.demo.dao;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.Set;

@Repository
public interface ClothRepository extends JpaRepository<Cloth, Long> {
    Set<Cloth> findByUserId(Long userId);

    Set<Cloth> findByUserIdAndCategory(Long userId, String category);

    Set<Cloth> findByUserIdAndSubcategory(Long userId, String subcategory);

    Cloth findByUserIdAndUserClothId(Long userId, int userClothId);

    void deleteByUserIdAndUserClothId(Long userId, int userClothId);

    @Query("SELECT COALESCE(MAX(c.userClothId), 0) FROM Cloth c WHERE c.user.id = :userId")
    int findMaxUserClothIdByUserId(@Param("userId") Long userId);
}
